package cn.kgc.javaweb.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author: mosin
 * @version: v1.0  2022/6/27
 */
public final class MapperUtil {

    private MapperUtil(){};

    private  static SqlSessionFactory factory;

    static {

        try {
            InputStream resourceAsStream = Resources.getResourceAsStream("config/mybatis-config.xml");
            factory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public  static SqlSession getSqlSession(){

        return  factory.openSession(true);

    }

}
